#!/usr/bin/ruby
# -*- ruby -*-
#
# http://programmingpraxis.com/2013/04/09/cyclic-equality/

require 'pp'

def min_ind(list)
  ind = nil
  val = nil

  list.each_index do |i|
    if ind.nil?
      ind = i
      val = list[i]
    elsif list[i] < val
      ind = i
      val = list[i]
    end
  end

  return [ind, val]
end

def cyclic_equals(left, right)
  return false if left.size != right.size

  left_offset = min_ind(left).first
  right_offset = min_ind(right).first

  left.each_index do |i|
    return false if left[(i + left_offset) % left.size] != right[(i + right_offset) % right.size]
  end

  return true
end

left  = []
right = []

current = left

ARGV.each do |c|
  if c == '/'
    current = right
  else
    current << c
  end
end

pp left
pp right
puts cyclic_equals(left, right)
